home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_Win.c
-
- Contains: window-handling routines.
-
- Written by: David H Nelson
-
- Copyright © 1993-1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- 05/09/95 SJF Tweaks for WWDC Demo
- --------------------------------------
-
- 05/08/95 SJF Remove the DnD handlers before we close the window.
- Remove the DnD handler installation section, as it's
- now done in CAS_Doc.c
- --------------------------------------
-
- 04/19/95 RB Modified scroll procedure to work with new
- CALib Layout API.
- --------------------------------------
- 03/31/95 RB Added code to Win_Close() to select the
- next document window
- --------------------------------------
- 03/29/95 RB Adding scrolling support for embedded parts
- --------------------------------------
- 03/27/95 DAS converted "theDoc->changed" reference into API call
- --------------------------------------
- 01/23/95 SJF Add CALib support for window allocation
- --------------------------------------
- 01/18/95 DHN Global function and variable name changes to suggest
- OOP design. Split app.c file into app.c, win.c, doc.c,
- item.c, and util.c.
- --------------------------------------
- 01/17/95 DAS changed all FrontWindow() calls to
- App_GetFrontDocWindow() to account for
- floating windows. Added Win_IsToolWindow().
- 1/16/95 DHN Massive improvements including, multiple window
- support, new window offsetting and naming, pref
- file support, file saving/reading, cursor tracking,
- PowerPC support, window update/activate in dialog
- filter, item drawing/selection/cut/copy (not paste),
- drag & drop (no drop yet), window scrolling, get
- info dialog, Select all menu item, Tools menu.
- through
- 12/23/94 DHN Created CASample from existing Light Software
- application framework.
- --------------------------------------
- 1/24/93 DHN Added code to ignore the enter key. Fixed page
- flipping animation by using current GrafPort in
- local coords rather than new GrafPort with global
- coords. Fixed findAgain to actually do something.
- 11/20/93 DHN Created.
- */
-
-
- #ifdef USE_CALIB
- #include "CALib.h"
- #include "CAS_CAUtil.h"
- #endif
-
- #include "CAS_Globals.h"
- #include "CAS_Misc.h"
- #include "CAS_Win.h"
- #include "CAS_Doc.h"
- #include "CAS_App.h"
- #include "CAS_ToolPalette.h"
- #include "CAS_Event.h"
- #include "CAS_Dialog.h"
-
- //---------------------------------------------------------------------------
- // Win_Update
-
- void Win_Update(
- WindowPtr theWindow )
- {
-
- BeginUpdate( theWindow );
- App_Update( theWindow );
- EndUpdate( theWindow );
-
- #ifdef USE_CALIB
- CADrawActiveBorder ();
- #endif
-
- }
-
-
- //---------------------------------------------------------------------------
- // Win_ShowSelection - make sure part of the selection is visible in the window.
-
- void Win_ShowSelection(
- WindowPtr theWindow )
- {
- DocPtr theDoc;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- #if 0
- short topLine;
- short bottomLine;
- short aLine;
-
- topLine = ((**theDoc->TEH).viewRect.top - (**theDoc->TEH).destRect.top) / theDoc->lineHeight;
- if (topLine < 0)
- topLine = 0;
- bottomLine = topLine + theDoc->LinesVisible;
- if (bottomLine > (**theDoc->TEH).nLines)
- bottomLine = (**theDoc->TEH).nLines;
-
- if ((**theDoc->TEH).selStart < (**theDoc->TEH).lineStarts[topLine] ||
- (**theDoc->TEH).selStart >= (**theDoc->TEH).lineStarts[bottomLine])
- {
- for (aLine = 0; (**theDoc->TEH).selStart > (**theDoc->TEH).lineStarts[aLine]; aLine++)
- ;
- aLine -= theDoc->LinesVisible / 2;
- if (GetControlValue( theDoc->scrollBar ) != aLine) // reduce flicker
- SetControlValue( theDoc->scrollBar, aLine ); // set the value.
- }
- AdjustTextToScrollBar( theDoc, bVisible );
- #endif
- }
-
- //----------------------------------------------------------------------
- // Adjust the scroll bars and any item rects/rgns in the window.
- // Also adjust the ScrollBarMax() if it needs to change.
-
- void Win_Adjust(
- WindowPtr theWindow )
- {
- DocPtr theDoc;
- short tempMax;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- // adjust the scrollBarRects
- theDoc->hScrollBarRect = theWindow->portRect;
- theDoc->hScrollBarRect.bottom += 1;
- theDoc->hScrollBarRect.left -= 1;
- theDoc->hScrollBarRect.top = theDoc->hScrollBarRect.bottom - SBARWIDTH;
- theDoc->hScrollBarRect.right -= (SBARWIDTH-2);
- HideControl( theDoc->hScrollBar );
- MoveControl( theDoc->hScrollBar, theDoc->hScrollBarRect.left, theDoc->hScrollBarRect.top );
- SizeControl(
- theDoc->hScrollBar,
- theDoc->hScrollBarRect.right - theDoc->hScrollBarRect.left,
- theDoc->hScrollBarRect.bottom - theDoc->hScrollBarRect.top );
-
- tempMax =
- (theDoc->documentRect.right - theDoc->documentRect.left) -
- (theDoc->hScrollBarRect.right - theDoc->hScrollBarRect.left);
- if (tempMax < 0)
- tempMax = 0;
- SetControlMaximum( theDoc->hScrollBar, tempMax );
-
- theDoc->vScrollBarRect = theWindow->portRect;
- theDoc->vScrollBarRect.right += 1;
- theDoc->vScrollBarRect.top -= 1;
- theDoc->vScrollBarRect.left = theDoc->vScrollBarRect.right - SBARWIDTH;
- theDoc->vScrollBarRect.bottom -= (SBARWIDTH-2);
- HideControl( theDoc->vScrollBar);
- MoveControl( theDoc->vScrollBar, theDoc->vScrollBarRect.left, theDoc->vScrollBarRect.top );
- SizeControl(
- theDoc->vScrollBar,
- theDoc->vScrollBarRect.right - theDoc->vScrollBarRect.left,
- theDoc->vScrollBarRect.bottom - theDoc->vScrollBarRect.top );
- tempMax =
- (theDoc->documentRect.bottom - theDoc->documentRect.top) -
- (theDoc->vScrollBarRect.bottom - theDoc->vScrollBarRect.top);
- if (tempMax < 0)
- tempMax = 0;
- SetControlMaximum( theDoc->vScrollBar, tempMax );
-
- // adjust the contentRect
- theDoc->contentRect = theWindow->portRect;
- theDoc->contentRect.right -= (SBARWIDTH-1);
- theDoc->contentRect.bottom -= (SBARWIDTH-1);
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- OSErr theErr;
-
- if (theDoc->partDocRef)
- {
- RgnHandle rootFrameRgn;
- RgnHandle tmpRgn;
- CAFrameRef rootFrameRef;
-
- rootFrameRgn = NewRgn();
- RectRgn (rootFrameRgn, &(theDoc->contentRect));
- rootFrameRef = CAGetRootFrameRef (theDoc->partDocRef);
- if (theErr = CAError())
- ; // handle the error
-
- tmpRgn = NewRgn();
- CopyRgn (rootFrameRgn, tmpRgn);
-
- CASetFrameRgn (theDoc->partDocRef, rootFrameRef, rootFrameRgn);
-
- //CAAdjustVisFrame (CAGetVisFrame (theDoc->partDocRef, rootFrameRef), tmpRgn, NULL);
-
- }
- }
- #endif
-
- ShowControl( theDoc->hScrollBar );
- ShowControl( theDoc->vScrollBar );
-
- // The scroll bar draws itself, let's avoid the redraw.
- //ValidRect( &theDoc->hScrollBarRect );
- //ValidRect( &theDoc->vScrollBarRect );
- }
-
- //---------------------------------------------------------------------------
- // Win_AdjustStdState - adjust the zoomed out size of the window based on the size
- // of the current printer paper.
- void Win_AdjustStdState(
- WindowPtr theWindow )
- {
- Rect screenRect;
- WStateData *wsdp;
- DocPtr theDoc;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- wsdp = (WStateData*)*((WindowPeek)theWindow)->dataHandle;
- if (wsdp == nil)
- return;
-
- #if 0
- // if there is no print handle, leave the stdState as is (size of main screen)
- // if (theDoc->hPrint)
- // {
- // Point thePt;
-
- // if (EmptyRect(&(**theDoc->hPrint).prInfo.rPage))
- // return;
- #endif
-
- wsdp->stdState = theDoc->documentRect;
- wsdp->stdState.bottom += SBARWIDTH-1; // account for width of scroll bar.
- wsdp->stdState.right += SBARWIDTH-1; // account for width of scroll bar.
-
- // move the top left to 0,0
- OffsetRect(&wsdp->stdState, -wsdp->stdState.left, -wsdp->stdState.top);
-
- #if 0
- // move the top-left stdState to the top-left of the window rect
- // thePt = topLeft(theWindow->portRect);
- // LocalToGlobal(&thePt);
- // OffsetRect(&wsdp->stdState, thePt.h, thePt.v);
- #endif
- RectLocalToGlobal( &wsdp->stdState );
-
- // if the bottom right corner is not on the screen, move the window to the
- // top left of the main screen and try again.
- if (!PtInRgn( botRight(wsdp->stdState), LMGetGrayRgn() ))
- {
- GetMainScreenRect( &screenRect ); /* get rect of main screen */
- OffsetRect(
- &wsdp->stdState, /* put at top,left of main screen */
- screenRect.left - wsdp->stdState.left + kInitWindowHOffset,
- screenRect.top - wsdp->stdState.top + kInitWindowVOffset);
-
- // make sure the right and bottom are on the screen.
- if (wsdp->stdState.right > screenRect.right)
- wsdp->stdState.right = screenRect.right - 4;
- if (wsdp->stdState.bottom > screenRect.bottom)
- wsdp->stdState.bottom = screenRect.bottom - 4;
- }
- // }
- }
-
- //----------------------------------------------------------------------
- // Scroll the contents of the window and update any exposed areas immediately.
-
- void Win_Scroll(
- WindowPtr theWindow,
- short hDist,
- short vDist )
- {
- DocPtr theDoc;
- RgnHandle theRgn;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- Point offset;
- CAFrameRef rootFrameRef;
- CATransform scrollTransform;
- OSErr theErr;
- CAVisFrame rootVisFrame;
-
- rootFrameRef = CAGetRootFrameRef( theDoc->partDocRef);
- if (theErr = CAError())
- ; // handle the error
-
- #if 0
- rootVisFrame = CAGetVisFrame (theDoc->partDocRef, rootFrameRef);
-
- CAGetVisFrameTransform(theDoc->partDocRef, rootFrameRef, &scrollTransform);
- offset.h = hDist; offset.v = vDist;
-
- CAMoveTransformBy( &scrollTransform, offset );
- CAAdjustVisFrame (rootVisFrame, NULL, &scrollTransform);
- #endif
- #if 1
- CAGetFrameTransform( theDoc->partDocRef, rootFrameRef, &scrollTransform );
- // Offset the root frame of the window being scrolled
- offset.h = hDist; offset.v = vDist;
-
- //CAMoveTransformBy( &scrollTransform, offset );
- offset.h = GetControlValue( theDoc->hScrollBar );
- offset.v = GetControlValue( theDoc->vScrollBar );
- CAMoveTransformTo( &scrollTransform, offset );
-
- CASetFrameTransform( theDoc->partDocRef, rootFrameRef, &scrollTransform );
- if (theErr = CAError())
- ; // handle the error
- #endif
-
- }
- #endif
-
- theRgn = NewRgn();
- ScrollRect( &theDoc->contentRect, hDist, vDist, theRgn );
- InvalRgn( theRgn );
- DisposeRgn( theRgn );
-
- Win_Update (theWindow);
-
- }
-
- //---------------------------------------------------------------------------
- // Win_Close - Close the window (after prompting to save changes)
-
- OSErr Win_Close(
- WindowPtr theWindow, Boolean* cancelled )
- {
- OSErr theErr = noErr;
-
- if (cancelled) *cancelled = false;
-
- if (Win_IsDAWindow( theWindow ))
- {
- CloseDeskAcc(((WindowPeek) theWindow)->windowKind);
- return theErr;
- }
- else if (Win_IsToolWindow( theWindow ))
- {
- if (theWindow == ToolPalette_GetWindow())
- ToolPalette_Dispose( theWindow );
- else
- DisposeWindow( theWindow );
- return theErr;
- }
- else if (Win_IsAppWindow( theWindow ))
- {
- DocPtr theDoc;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- if (Doc_GetDirty( theDoc ))
- {
- short response;
- Str255 theName;
- Str255 theVerb;
-
- GetWTitle( theWindow, theName );
- GetIndString( theVerb, kStrings, itClosing ); // $$$$$ don't forget itQuitting
- ParamText( theName, theVerb, "\p", "\p" );
- SetCursor( &qd.arrow );
-
- iOKITEM = kSaveButton;
- iCancelITEM = kCancelButton;
-
- App_ForceActivateFrontWindow( false );
- response = Alert( kSaveChangesDialog, gWindowEventFilterUPP );
- App_ForceActivateFrontWindow( true );
-
- if (response == kCancelButton)
- {
- if (cancelled) *cancelled = true;
- return theErr;
- }
- else if (response == kSaveButton)
- {
- // save the file, creating a new file if needed.
- theErr = Doc_Save( theDoc );
- }
- else // kDontSaveButton
- {
- }
- }
-
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- CARemoveTrackingHandler( gDragTrackingHandlerUPP, theWindow );
- CARemoveReceiveHandler( gDragReceiveHandlerUPP, theWindow );
-
- CAUnregisterWindow( theWindow );
- }
- #endif
-
- // get rid of the drag mgr handlers
- // SJF - NOTE: Gotta do this before closing the document or
- // there's no docRef to work off of.
- if (hasDragMgr)
- {
- #ifdef USE_CALIB
- if (!gCALibExists)
- {
- RemoveTrackingHandler( gDragTrackingHandlerUPP, theWindow );
- RemoveReceiveHandler( gDragReceiveHandlerUPP, theWindow );
- }
- #else
- RemoveTrackingHandler( gDragTrackingHandlerUPP, theWindow );
- RemoveReceiveHandler( gDragReceiveHandlerUPP, theWindow );
- #endif
- }
-
- Doc_Close( theDoc );
- App_LogCloseDocument (theDoc);
-
- // close the file (if it exists)
- if (theDoc->fileRefNum != 0)
- {
- theErr = FSClose( theDoc->fileRefNum );
- }
-
- // release the undo memory.
- Doc_DisposeUndo( theDoc );
-
- // get rid of the scroll bars
- DisposeControl( theDoc->hScrollBar );
- DisposeControl( theDoc->vScrollBar );
-
- // finally, get rid of the window itself.
- DisposeWindow( theWindow );
-
- // Make sure the next window gets selected
- App_SetFrontDocWindow( App_GetFrontDocWindow() );
-
- return theErr; // everything went OK.
- }
-
- return theErr;
- }
-
- //---------------------------------------------------------------------------
- // Win_New - create a B/W or color window.
-
- WindowPtr Win_New(
- WindowPtr behindWindow,
- Rect *windowRect )
- {
- WindowPtr theWindow;
- OSErr theErr;
-
- if (hasColorQD)
- theWindow = GetNewCWindow( kWindowID, nil, behindWindow );
- else
- theWindow = GetNewWindow( kWindowID, nil, behindWindow );
-
- // if there is no window, get out.
- if (theWindow == nil)
- return nil;
-
- SetPort( theWindow );
-
- MoveWindow( theWindow, windowRect->left, windowRect->top, false );
- SizeWindow(
- theWindow, windowRect->right - windowRect->left,
- windowRect->bottom - windowRect->top, true );
-
- // make sure our window is visible on screen
- Win_CheckWindowPosition( theWindow );
-
- #if 0 // Wait until this window has been registered with CALib
- // (if present) to register the DnD handlers...
- // install the drag handlers on the window.
- if (hasDragMgr)
- {
- theErr = InstallTrackingHandler( gDragTrackingHandlerUPP, theWindow, nil );
- if (theErr == noErr)
- {
- theErr = InstallReceiveHandler( gDragReceiveHandlerUPP, theWindow, nil );
- if (theErr != noErr)
- RemoveTrackingHandler( gDragTrackingHandlerUPP, theWindow );
- }
- }
- #endif
-
- return theWindow;
- }
-
- //---------------------------------------------------------------------------
- // Win_IsVisible - create a B/W or color window.
-
- Boolean Win_IsVisible(
- WindowPtr theWindow )
- {
- return ((theWindow != nil) && ((WindowPeek)theWindow)->visible);
- }
-
-
- //---------------------------------------------------------------------------
- // Win_DoBackClicks - decide whether a click in a non-front window does
- // more than bring the window to the front.
-
- Boolean Win_DoBackClicks(
- WindowPtr theWindow )
- {
- return true;
- }
-
-
- //---------------------------------------------------------------------------
- // Win_IsFloater - create a B/W or color window.
-
- Boolean Win_IsFloater(
- WindowPtr theWindow )
- {
- short targetWKind;
- Boolean isFloater;
-
- isFloater = false;
- if (theWindow != nil)
- {
- targetWKind = ((WindowPeek)theWindow)->windowKind;
- isFloater = (targetWKind == WINDOWKIND_FLOATING);
- }
-
- return isFloater;
- }
-
- //---------------------------------------------------------------------------
- // Win_SetFloaterKind - create a B/W or color window.
-
- short Win_SetFloaterKind(
- WindowPtr theWindow )
- {
- short oldWKind;
-
- if (theWindow == nil)
- return nil;
-
- /* return the old windowKind to the caller, as a convenience */
- oldWKind = ((WindowPeek)theWindow)->windowKind;
-
- /* wedge the windowKind field so that the window can be identified as a floating window */
- ((WindowPeek)theWindow)->windowKind = WINDOWKIND_FLOATING;
-
- return oldWKind;
- }
-
- //---------------------------------------------------------------------------
- // Win_SendActivateEvent - create a B/W or color window.
-
- void Win_SendActivateEvent(
- WindowPtr theWindow,
- Boolean isActive )
- {
- EvQElPtr queueSpot;
- OSErr errStat;
-
- if (!Win_IsVisible( theWindow ))
- return;
-
- errStat = PPostEvent( activateEvt, (long)theWindow, &queueSpot );
- if ((errStat == noErr) && (queueSpot != nil))
- {
- if (isActive)
- queueSpot->evtQModifiers |= activeFlag;
- else
- queueSpot->evtQModifiers &= ~activeFlag;
- }
-
- #if defined(Debugging)
- if ((errStat != noErr) || (queueSpot == nil))
- DEBUGSTR( "\pWin_SendActivateEvent: posting event didn't work" );
- #endif
- }
-
- //---------------------------------------------------------------------------
- // Win_ShowHide - create a B/W or color window.
-
-
- void Win_ShowHide(
- WindowPtr theWindow,
- Boolean showIt )
- {
- if ((theWindow == nil) || (showIt == Win_IsVisible( theWindow )))
- return;
-
- ShowHide( theWindow, showIt );
- if (showIt && Win_IsFloater( theWindow ))
- HiliteWindow( theWindow, true );
- }
-
- //---------------------------------------------------------------------------
- // Win_DragWindow_Better - similar to DragWindow, but without
- // forcing the target window to the front
-
- void Win_DragWindow_Better(
- WindowPtr theWindow,
- Point theGlobalPt,
- Rect *boundsR )
- {
- CGrafPtr cDeskPort;
- GrafPtr savedPort;
- RgnHandle wOutline, wArea, savedClip;
- Rect slopR;
- Point localOffset;
- long longDeltaPt;
-
- if ((theWindow == nil) || (boundsR == nil) || EmptyRect( boundsR ))
- return;
-
- GetPort( &savedPort );
- SetPort( theWindow );
- localOffset = theGlobalPt;
- GlobalToLocal( &localOffset );
-
- GetCWMgrPort( &cDeskPort );
- SetPort( (GrafPtr)cDeskPort );
-
- wArea = NewRgn();
- wOutline = NewRgn();
- savedClip = NewRgn();
-
- CopyRgn( ((CWindowRecord*)theWindow)->strucRgn, wArea );
- UnionRgn( wArea, ((CWindowRecord*)theWindow)->contRgn, wArea );
- CopyRgn( wArea, wOutline );
- InsetRgn( wArea, 1, 1 );
- DiffRgn( wOutline, wArea, wOutline );
-
- GetClip( savedClip );
- ClipRect( boundsR );
-
- slopR = *boundsR;
- GlobalToLocal( &theGlobalPt );
- longDeltaPt =
- DragGrayRgn(
- wOutline, theGlobalPt, boundsR, &slopR,
- noConstraint, (DragGrayRgnUPP)nil );
-
- if ((longDeltaPt != 0x80008000) && (longDeltaPt != 0L))
- MoveWindow(
- theWindow,
- (theGlobalPt.h - localOffset.h) + LoWord( longDeltaPt ),
- (theGlobalPt.v - localOffset.v) + HiWord( longDeltaPt ),
- false );
-
- SetClip( savedClip );
-
- DisposeRgn( wArea );
- DisposeRgn( wOutline );
- DisposeRgn( savedClip );
-
- SetPort( savedPort );
- }
-
- //---------------------------------------------------------------------------
- // Win_IsDAWindow - return true if theWindow is a Desk Accessory windows.
-
- Boolean Win_IsDAWindow(
- WindowPtr theWindow )
- {
- if (theWindow == nil)
- return false;
- else // DA windows have negative windowKinds
- return (((WindowPeek)theWindow)->windowKind < 0);
- }
-
- //---------------------------------------------------------------------------
- // Win_IsAppWindow - return true if theWindow is one of our application's windows.
-
- Boolean Win_IsAppWindow(
- WindowPtr theWindow )
- {
- if (theWindow == nil)
- return false;
- else if (CAIsPartWindow (theWindow))
- return false;
- else
- return (((WindowPeek)theWindow)->windowKind == userKind);
- }
-
- //---------------------------------------------------------------------------
- // Win_IsToolWindow - return true if theWindow is one of our application's
- // windows, but not a doc window.
-
- // DAS: added.
- Boolean Win_IsToolWindow(
- WindowPtr theWindow )
- {
- return Win_IsFloater( theWindow );
- }
-
- //---------------------------------------------------------------------------
- // Win_IsDialogWindow - return true if theWindow is a dialog window.
-
- Boolean Win_IsDialogWindow(
- WindowPtr theWindow )
- {
- if (theWindow == nil)
- return false;
- else
- return (((WindowPeek)theWindow)->windowKind == dialogKind);
- }
-
- //----------------------------------------------------------------------
- // Win_CheckWindowPosition - makes sure the window title bar is on a visible
- // part of the screen and the window is at least as big as the min size
- // in the 'wrct' rsrc. If not move it onto the top left of the main screen and
- // fix its size. This should be called before the window is made visible.
-
- void Win_CheckWindowPosition(
- WindowPtr theWindow )
- {
- Rect boundsRect, screenRect, growRect;
- Rect **theRectHandle;
-
- theRectHandle = (Rect**)GetIndResource( 'wrct', 1 );
- if (theRectHandle != nil)
- growRect = **theRectHandle;
- else
- // set a default growRect.
- SetRect( &growRect, 100, 100, 0x7FFF, 0x7FFF );
-
- boundsRect = theWindow->portRect; // get bounds rect of window
-
- // check the minimum width
- if (boundsRect.right - boundsRect.left < growRect.left)
- SizeWindow(
- theWindow, growRect.left,
- theWindow->portRect.bottom - theWindow->portRect.top, false );
-
- // check the minimum height
- if (boundsRect.bottom - boundsRect.top < growRect.top)
- SizeWindow(
- theWindow,
- theWindow->portRect.right - theWindow->portRect.left,
- growRect.top, false );
-
- // get bounds rect of window, again
- boundsRect = theWindow->portRect;
-
- RectLocalToGlobal( &boundsRect );
-
- // use the lower 10 pixels of the title bar
- boundsRect.bottom = boundsRect.top;
- boundsRect.top -= 10;
-
- // window is not within gray region
- if (!RectInRgn( &boundsRect, LMGetGrayRgn() ))
- {
- // get rect of main screen
- GetMainScreenRect( &screenRect );
- MoveWindow(
- theWindow, screenRect.left + kInitWindowHOffset,
- screenRect.top + kInitWindowVOffset, false );
- }
- }
-
- //---------------------------------------------------------------------------
- WindowPtr Win_CenterWindow(
- WindowPtr theWindow )
- {
- Rect rWindow, rScreen;
-
- GetMainScreenRect( &rScreen );
- rScreen.top += GetMBarHeight() + 4;
- rWindow = theWindow->portRect;
-
- rCenterRectInRect( &rScreen, &rWindow );
- MoveWindow( theWindow, rWindow.left, rWindow.top, false );
-
- return theWindow;
- }
-
- //---------------------------------------------------------------------------
- WindowPtr Win_CenterWindowOnParentWindow(
- WindowPtr theWindow )
- {
- WindowPtr topWindow;
- Rect rWindow, rParent;
-
- if (theWindow != nil)
- {
- topWindow = App_GetFrontDocWindow();
- if (topWindow == nil)
- GetMainScreenRect( &rParent );
- else
- rParent = topWindow->portRect;
- RectLocalToGlobal( &rParent );
-
- if (theWindow == nil)
- GetMainScreenRect( &rWindow );
- else
- rWindow = theWindow->portRect;
-
- rCenterRectInRect( &rParent, &rWindow );
- MoveWindow( theWindow, rWindow.left, rWindow.top, false );
- }
-
- return theWindow;
- }
-
- //---------------------------------------------------------------------------
- WindowPtr Win_CenterTWindow(
- WindowPtr theWindow,
- short iTitleSize )
- {
- Rect rWindow, rScreen;
-
- GetMainScreenRect( &rScreen );
- rScreen.top += GetMBarHeight();
- rWindow = theWindow->portRect;
- rWindow.top -= iTitleSize;
-
- rCenterRectInRect( &rScreen, &rWindow );
- MoveWindow( theWindow, rWindow.left, rWindow.top+iTitleSize, false );
-
- return theWindow;
- }
-
- //---------------------------------------------------------------------------
- void Win_CenterShowWindow(
- WindowPtr theWindow )
- {
- if (theWindow != nil)
- ShowWindow( Win_CenterWindow( theWindow ) );
- }
-
- //---------------------------------------------------------------------------
- // handle update and activate events for our doc windows.
-
- pascal Boolean bWindowEventFilter(
- DialogPtr theDialog,
- EventRecord *theEvent,
- short *itemHit )
- {
- // Note: return true if we know we handled an event, otherwise fall through
- // to the bGenericDialogFilter.
- switch (theEvent->what)
- {
- case updateEvt:
- // try to handle the activate; assume we did not handle it.
- Event_HandleUpdateEvent( theEvent );
- break;
-
- case activateEvt:
- // try to handle the activate; assume we did not handle it.
- Event_HandleActivateEvent( theEvent );
- break;
-
- default: // for any other event, fall through.
- break;
- }
-
- return bGenericDialogFilter(theDialog, theEvent, itemHit );
- }
-
- //---------------------------------------------------------------------------
- // handle update and activate events for our doc windows in CustomPutFile
- // and CustomGetFile. Don't call our bGenericDialogFilter.
-
- pascal Boolean bWindowEventYDFilter(
- DialogPtr theDialog,
- EventRecord *theEvent,
- short *itemHit,
- Ptr yourData )
- {
-
- // Note: return true if we know we handled an event, otherwise fall through
- // to the bGenericDialogFilter.
- switch (theEvent->what)
- {
- case updateEvt:
- // try to handle the activate; assume we did not handle it.
- Event_HandleUpdateEvent( theEvent );
- break;
-
- case activateEvt:
- // try to handle the activate; assume we did not handle it.
- Event_HandleActivateEvent( theEvent );
- break;
-
- default: // for any other event, fall through.
- break;
- }
-
- return false; // we did not handle the event.
-
- // return bWindowEventFilter(theDialog, theEvent, itemHit );
- }
-
-
-
-